package top.xiaoshuaila.searescue.task;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.xiaoshuaila.searescue.pojo.Helmet;
import top.xiaoshuaila.searescue.service.MqttDataDeal2;
import top.xiaoshuaila.searescue.service.MqttService;

import java.util.HashMap;
import java.util.Map;

@Component
public class MqttTask {
    @Autowired
    private MqttService mqttService;
    @Autowired
    private MqttDataDeal2 mqttDataDeal;
    @Scheduled(cron = "0/7 * * * * ?")
    private void open(){
        Map<Integer,Integer>lostTime= mqttDataDeal.lostTime;
        mqttService.lost.clear();
        for(Integer a:lostTime.keySet())
        {
            lostTime.put(a,lostTime.get(a)+5);
            if(lostTime.get(a)>30)
                mqttService.lost.add(a);
        }
        new Thread(new Runnable() {
            @Override
            public void run() {
                mqttService.PubAll();
            }
        }).start();
    }
}